package com.yanqu.road.entity.wingroom.chakra.data;

import com.yanqu.road.entity.DataObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

public class UserWingRoomChakra extends DataObject {

    /**
     * 玩家ID
     */
    private Long userId;
    /**
     * 厢房风水
     */
    private Long windWater;
    /**
     * 厢房风水上限
     */
    private Long windWaterLimit;
    /**
     * 风水等级
     */
    private int windWaterLevel;
    /**
     * 命盘经验
     */
    private Long chakraExp;
    /**
     * 命盘等级
     */
    private int chakraLevel;
    /**
     * 抽取次数
     */
    private int drawNum;
    /**
     * 创建时间
     */
    private Long createTime;
    /**
     * 更新时间
     */
    private Long updateTime;

    /**
     * 待处理的【四象，命格】数据
     */
    private List<UserWingRoomChakraDetail> waitChakraDetail = new ArrayList<>();

    /**
     * 每日拜访的玩家次数
     */
    private Map<String, Integer> dailyVisitData = new HashMap<>();

    /**
     * 上次清除【每日拜访的玩家次数】时间
     */
    private long lastClearVisitTime = 0;

    public void setUserId(Long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public Long getUserId() {
        return userId;
    }

    public void setWindWater(Long windWater) {
        if(this.windWater != windWater) {
            this.windWater = windWater;
            setUpdateOption();
        }
    }

    public Long getWindWater() {
        return windWater;
    }

    public Long getWindWaterLimit() {
        return windWaterLimit;
    }

    public void setWindWaterLimit(Long windWaterLimit) {
        if(this.windWaterLimit != windWaterLimit) {
            this.windWaterLimit = windWaterLimit;
            setUpdateOption();
        }
    }

    public void setWindWaterLevel(int windWaterLevel) {
        if(this.windWaterLevel != windWaterLevel) {
            this.windWaterLevel = windWaterLevel;
            setUpdateOption();
        }
    }

    public int getWindWaterLevel() {
        return windWaterLevel;
    }

    public void setChakraExp(Long chakraExp) {
        if(this.chakraExp != chakraExp) {
            this.chakraExp = chakraExp;
            setUpdateOption();
        }
    }

    public Long getChakraExp() {
        return chakraExp;
    }

    public void setChakraLevel(int chakraLevel) {
        if(this.chakraLevel != chakraLevel) {
            this.chakraLevel = chakraLevel;
            setUpdateOption();
        }
    }

    public int getChakraLevel() {
        return chakraLevel;
    }

    public void setCreateTime(Long createTime) {
        if(this.createTime != createTime) {
            this.createTime = createTime;
            setUpdateOption();
        }
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setUpdateTime(Long updateTime) {
        if(this.updateTime != updateTime) {
            this.updateTime = updateTime;
            setUpdateOption();
        }
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public List<UserWingRoomChakraDetail> getWaitChakraDetail() {
        return waitChakraDetail;
    }

    public void setWaitChakraDetail(List<UserWingRoomChakraDetail> list) {
        if(this.waitChakraDetail != list) {
            this.waitChakraDetail = list;
            setUpdateOption();
        }
    }

    public void addWaitChakraDetail(UserWingRoomChakraDetail waitChakraDetail) {
        this.waitChakraDetail.add(waitChakraDetail);
        setUpdateOption();
    }

    public void addWaitChakraDetailFirst(UserWingRoomChakraDetail waitChakraDetail) {
        this.waitChakraDetail.add(0, waitChakraDetail);
        setUpdateOption();
    }

    public void removeWaitChakraDetailFirst() {
        this.waitChakraDetail.remove(0);
        setUpdateOption();
    }

    public void clearWaitChakraDetail() {
        this.waitChakraDetail.clear();
        setUpdateOption();
    }

    public Map<String, Integer> getDailyVisitData() {
        return dailyVisitData;
    }

    public void setDailyVisitData(Map<String, Integer> dailyVisitData) {
        if(this.dailyVisitData != dailyVisitData) {
            this.dailyVisitData = dailyVisitData;
            setUpdateOption();
        }
    }

    public void clearDailyVisitData() {
        this.dailyVisitData.clear();
        setUpdateOption();
    }

    public void addDailyVisitData(long beVisitUserId) {
        int num = this.dailyVisitData.getOrDefault(String.valueOf(beVisitUserId), 0);
        this.dailyVisitData.put(String.valueOf(beVisitUserId), num + 1);
        setUpdateOption();
    }

    public long getLastClearVisitTime() {
        return lastClearVisitTime;
    }

    public void setLastClearVisitTime(long lastClearVisitTime) {
        if(this.lastClearVisitTime != lastClearVisitTime) {
            this.lastClearVisitTime = lastClearVisitTime;
            setUpdateOption();
        }
    }

    public int getDrawNum() {
        return drawNum;
    }

    public void setDrawNum(int drawNum) {
        if(this.drawNum != drawNum) {
            this.drawNum = drawNum;
            setUpdateOption();
        }
    }

    /**
     * 获取基础风水值（有上限，无加成）
     * @return
     */
    public long getRealWindWater() {
        return Math.min(this.windWater, this.windWaterLimit);
    }
}
